﻿

************************************************************************************************
* Constructing data set to "Public Health Policy At Scale.."
************************************************************************************************

************************************************************************************************
* Full population born 1970-2014 from birth registries
* Calculate birth order
*************************************************************************************************


global rawStata "X:\Data\Workdata\707116\Stata"
global temp2 "X:\Data\Workdata\707116\ChildVax\02_temp\Nov2019" 

set mem 2g
set more off
set linesize 255


use $temp2\lpr1996.dta
append using $temp2\lpr2014.dta
tempfile t1 
save `t1' 

bysort mpnr_mfr: g i=_n
keep if i==1 //keep only unique id of moms 
keep mpnr_mfr
rename mpnr_mfr mor_id 
tempfile t2
save `t2' 


use mor_id pnr foed_dag using  $rawStata\grundvive1980, clear 
g byear=year(foed_dag) 
drop if byear>1972 

merge m:1 mor_id using `t2' 

keep if _merge==3 
drop byear 
rename mor_id  mpnr_mfr
append using `t1' 

g birthday=mdy(bmonth, bday, byear) 
format birthday %td 
replace birthday=foed_dag if _merge==3
sort  mpnr_mfr birthday 
by  mpnr_mfr: g border = _n 
replace border=. if mpnr_mfr =="" 

drop if _merge==3 

drop _merge 

save $temp2\births19732014.dta, replace 
